package com.dubbo.zyx.controller;

import com.dubbo.zyx.api.UserService;
import com.dubbo.zyx.model.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 描述说明: 用户请求客户端的入口
 *
 * @author DQing
 * @version 1.0
 * @className UserController
 * @date 2020/9/2 17:07
 */
@RestController
@Slf4j
public class UserController {
    @Reference(check=false)
    UserService userService;

    @RequestMapping("/user/{userId}")
    @HystrixCommand(fallbackMethod = "failGetUser")
    public User getUser(@PathVariable("userId")String userId){
        return userService.getUser(userId);
    }

    public User failGetUser(@PathVariable("userId")String userId){
        User user = new User();
        user.setUserName("NUll");
        return user;
    }
}
